package models

import "github.com/astaxie/beego/orm"

type Teacher struct {
	Id       string   `orm:"column(id);pk"`
	Name     string   `orm:"column(name);size(50)"`
	Password string   `orm:"column(password);size(50)"`
	Phone    string   `orm:"column(phone);size(50)"`
	//Clazzs   []*Clazz `orm:"rel(m2m);rel_through(go_hw/models.StudentClazz)"`
}

func init() {
	orm.RegisterModel(new(Teacher))
}
func (m *Teacher) TableName() string {
	return "teacher"
}

// 通过用户ID获取用户信息及用户所属的角色
func GetTeacherById(ormObj orm.Ormer, id string) (v *Teacher, err error) {
	v = &Teacher{Id: id}
	if err = ormObj.QueryTable(&Teacher{}).Filter("Id", id).RelatedSel().One(v); err == nil {
		// 获取关系字段，ormObj.LoadRelated(v, "Roles") 这是关键
		// 查找该用户所属的角色
		//if _, err = ormObj.LoadRelated(v, "Clazzs"); err != nil {
			//return nil, err
		//}
		return v, nil
	}
	return nil, err
}
